/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CapadeDatos;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JOptionPane;
import modelo.beanalumno;
import modelo.beanlista;
import modelo.beansemestre;

/**
 *
 * @author jxtx
 */
public class daodet_mat {


public static  ArrayList semestretiene( String cod_mat ){
         ArrayList lista = new  ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="CALL `proc_lossempas`('"+cod_mat+"');"; // PROCEDIMIENTO ALMACENADO
            ResultSet rs =stm.executeQuery(sql);
           while (rs.next()){
                   beansemestre y  = new  beansemestre();
                   y.setCod_sem(rs.getString(1));
                   y.setCod_carrera(rs.getString(2));
                   y.setDescipcion(rs.getString(3));
                   y.setCondicion(rs.getString(4));
                   y.setCod_per(rs.getString(5));
                   y.setTurno(rs.getString(6));
                   y.setFechadetmatr(rs.getString(7));
                   y.setEstado(rs.getString(8));
                   y.setUnirep(rs.getString(9));
                   JOptionPane.showMessageDialog(null,"encontrado "+y.getCod_carrera());
                   lista.add(y);
        }
     }catch(Exception e){
         System.out.print(e);
   }
      /*      Iterator itr = lista.iterator();
            beansemestre list=new beansemestre();
            list=(beansemestre) itr.next();
   JOptionPane.showMessageDialog(null,"encontrado "+list.getCod_carrera());
*/
      /*itr.next();
      itr.next();
      list =  (beanlista)itr.next();
                JOptionPane.showMessageDialog(null,"--->"+list.getNombre());
        */
         return lista;


   }
public static  ArrayList semestrepodriatener( String cod_mat ){
         ArrayList lista = new  ArrayList();
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="CALL `proc_posiblesemestres`('"+cod_mat+"')"; // PROCEDIMIENTO ALMACENADO
            ResultSet rs =stm.executeQuery(sql);
           while (rs.next()){
                    beansemestre y  = new  beansemestre();
                   y.setCod_sem(rs.getString(1));
                   y.setCod_carrera(rs.getString(5));
                   y.setDescipcion(rs.getString(3));
                   y.setCod_per(rs.getString(2));
                   y.setTurno(rs.getString(4));
                  lista.add(y);
        }
     }catch(Exception e){System.out.print(e);
   }
            Iterator itr = lista.iterator();
            beansemestre list=new beansemestre();
      /*itr.next();
      itr.next();
      list =  (beanlista)itr.next();
                JOptionPane.showMessageDialog(null,"--->"+list.getNombre());
        */
         return lista;


   }
public static beanalumno alumno(String cod_mat){

    beanalumno p  = new  beanalumno();

     try{
            Connection cn = ConexionBD.getInstance().getConnection();
            Statement stm = cn.createStatement();
            String sql ="CALL `proc_unalumno`('"+cod_mat+"')"; // PROCEDIMIENTO ALMACENADO
             ResultSet rs =stm.executeQuery(sql);

                    while (rs.next()){
                   p.setNombre(rs.getString(1));
                   p.setApepat(rs.getString(2));
                   p.setApemat(rs.getString(3));
                   p.setCarrera(rs.getString(4));
                   p.setCod_mat(rs.getString(5));
  }

   JOptionPane.showMessageDialog(null,"encontrado "+ p.getApepat());

            if(rs.wasNull()){
                JOptionPane.showMessageDialog(null,"NO INGRESADO");

            }
            else {
              

        }
                JOptionPane.showMessageDialog(null,"encontrado "+ cod_mat);
             
    }catch(Exception e){System.out.print(e);
   }
        return p;
   }

public void insertardetallematricula(String cod_mat,
        String fecha,String cod_sem,String cod_cond,String unirep){
      
    try{
            Connection cn = ConexionBD.getInstance().getConnection();
           
            Statement stm = cn.createStatement();
            
            String sql ="CALL inseertardet ('"+cod_mat+"','"+fecha+"','"+cod_sem+"','"+cod_cond+"','"+unirep+"');";
            ResultSet rs =stm.executeQuery(sql);
            if(rs.wasNull()){
               JOptionPane.showMessageDialog(null,"NO INGRESADO +");
            }
            else {

                JOptionPane.showMessageDialog(null,"INGRESADO+desc+ '"+cod_mat+"',"+fecha+",'"+cod_sem+"','"+cod_cond+"'");
             }
    }catch(Exception e){System.out.print(e);
   }
   }


}
